Design Principles
Tags: #◇Computer Science #◇CCPROG3 #◇Design Principles #◇Conceptual #◇M11
◇Key Definitions
Design Principles are guidelines that help software engineers design better, more maintainable, and scalable object-oriented software. The most prominent are the SOLID principles.
◇Theoretical Framework
SOLID is an acronym for five design principles:
- Single Responsibility Principle (SRP): A class should have one, and only one, reason to change.
- Open/Closed Principle (OCP): Software entities should be open for extension, but closed for modification.
- Liskov Substitution Principle (LSP): Subtypes must be substitutable for their base types without altering the correctness of the program.
- Interface Segregation Principle (ISP): Clients should not be forced to depend on interfaces they do not use.
- Dependency Inversion Principle (DIP): High-level modules should not depend on low-level modules. Both should depend on abstractions.
◇Important Formulas
Coupling vs. Cohesion: Good design aims for Low Coupling (dependencies between modules are minimized) and High Cohesion (responsibilities within a module are strongly related).
◇Worked Examples
Violating SRP: A User class that handles user data storage, user validation, and email notification.
Fixing SRP: Create separate classes: UserRepository (storage), UserValidator (validation), and EmailService (notification).
◇References & Navigation
- Previous Topic: ◇Files I-O (via Streams)
- Related Notes: ◇Overview of Programming Languages
ACTIVE RECALL VERIFICATION
Select an answer to verify conceptual comprehension and reveal the technical rationale.
What does the Single Responsibility Principle (SRP) dictate?
According to the Open/Closed Principle (OCP), how should software entities be designed?
Which principle states that subtypes must be substitutable for their base types without altering program correctness?
What is the goal of having "High Cohesion" in software design?
How would you fix a User class that handles user data storage, validation, and email notifications to adhere to SRP?